package com.ltedu.user.controller;


import com.ltedu.common.utils.IpUtils;
import com.ltedu.common.validate.Create;
import com.ltedu.common.vo.Result;
import com.ltedu.user.domain.vo.LoginVO;
import com.ltedu.user.domain.vo.RegisterVO;
import com.ltedu.user.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author Jerry
 * @since 2020-11-26
 */
@RestController
@RequestMapping("/user/member")
public class MemberController {

    @Autowired
    private MemberService memberService;

    /**
     * 用户注册
     *
     * @param registerVO 注册签证官
     * @return {@link Result}
     */
    @PostMapping("/register")
    public Result register(@Validated(Create.class) @RequestBody RegisterVO registerVO) {
        return Result.ok(memberService.register(registerVO));
    }

    /**
     * 用户登录
     *
     * @param loginVO 登录签证官
     * @param request 请求
     * @return {@link Result}
     */
    @PostMapping("/login")
    public Result login(@Validated @RequestBody LoginVO loginVO, HttpServletRequest request) {
        return memberService.login(loginVO, IpUtils.getIpAddr(request));
    }

}

